package com.csdn.leon.view.dialog;

import com.csdn.leon.base.R;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class CustomDialog extends Dialog implements
		android.view.View.OnClickListener {
	int layoutRes;// 布局文件
	Context context;
	private Button cancel;
	private Button confirm;
	private TextView textview;
	private DialogListener listener;

	public CustomDialog(Context context) {
		super(context);
	}

	/**
	 * 自定义布局的构造方法
	 * 
	 * @param context
	 * @param resLayout
	 */
	public CustomDialog(Context context, int resLayout) {
		super(context);
		this.context = context;
		this.layoutRes = resLayout;
	}

	/**
	 * 自定义主题及布局的构造方法
	 * 
	 * @param context
	 * @param theme
	 * @param resLayout
	 */
	public CustomDialog(Context context, int theme, int resLayout) {
		super(context, theme);
		this.context = context;
		this.layoutRes = resLayout;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(layoutRes);
		setCancelable(true);
		initView();
	}

	private void initView() {
		cancel = (Button) findViewById(R.id.cancel_btn);
		confirm = (Button) findViewById(R.id.confirm_btn);
		cancel.setOnClickListener(this);
		confirm.setOnClickListener(this);
		textview = (TextView) findViewById(R.id.content_dialog);
	}

	public interface DialogListener {
		public void isCancel(boolean flag);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.cancel_btn:
			listener.isCancel(false);
			break;
		case R.id.confirm_btn:
			listener.isCancel(true);
			break;
			default:
				
				break;
		}
	}

	public void setDialogListener(DialogListener listener) {
		this.listener = listener;
	}
	
	public void setTextContent(String content){
		if(textview!=null){
		textview.setText(content);
		}
	}
}
